use PlPN qw(PN);
use Pod::Text;
use strict;

my $Parser = new Pod::Text;

=pod

Prints documentation for the given script to the output window.

All the documentation in the file in which the script was registered will be
printed, so the documentation printed may refer to more than one script.

If called without a parameter, will print this documentation.

=cut

PlPN->RegisterScript('example', 'Script Docs', sub {
	# must match the above
	my ($group, $script) = ('example', 'Script Docs');
	
	my $key = PN->InputBox("Script Docs",
		"Please enter the group and name of the script, " .
		"separated by a forward slash (group/name)");
	
	if ($key) {
		($group, $script) = split m:/:, $key;
	}
	
	my $file = $PlPN::ScriptFiles{$group}{$script} or
		warn "Unable to find the source file for '$group/$script'" and
		return;
	
	my $output;
	open OUTPUT, '>', \$output;
	
	$Parser->parse_from_file($file, *OUTPUT);
	
	close OUTPUT;
	
	$output ||= "No documentation found for $group/$script";
	
	PN->GetGlobalOutputWindow->ShowOutput;
	PN->GetGlobalOutputWindow->AddToolOutput($output);
});
